home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 09 Racing and Sports AI / 04 Adzima / aiNavigation.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-19  |  4.8 KB  |  172 lines

  1. #ifndef AI_NAVIGATION_H
  2. #define AI_NAVIGATION_H
  3.  
  4. #include "aiMath.h"
  5. #include "aiVehicle.h"
  6.  
  7. class aiPath;
  8. class aiObstacle;
  9.  
  10. struct aiRouteNode
  11. {
  12.     aiRouteNode();
  13.     void Reset();
  14.     aiObstacle *m_pObstacle;
  15.     Vector3 Vtx;
  16.     float m_fCumAngle;
  17.     float m_fCumDist;
  18.  
  19.     short m_nSRd;
  20.     short m_nSVIdx;
  21.     short m_nType;
  22.     short m_nTurnId;
  23.     short m_nObsType;
  24.     short m_nOnRoad;    // 0: Off the road, 1: On the road, 2: On the sidewalk
  25. };
  26.  
  27. class aiNavigation 
  28. {
  29.     public:
  30.         aiNavigation();
  31.         ~aiNavigation();
  32.  
  33.         void Init(int nId,char *pGeoFile);
  34.         void Reset();
  35.         void RegisterRoute(short *panRoute,short nNumRouteNodes,const Vector3& Destination,
  36.                            const Vector3& DestHeading,int nNumRepeats=0,float fTargetSpeed=0.f,
  37.                            float fDestOffset=0.f,float fTurnVelFactor=1.f,float fBrakeThreshold=.7f,
  38.                            float fRoutePlanDist=75.f);
  39.  
  40.         void DriveRoute();
  41.  
  42.         int  State(){return m_nState;}
  43.         void State(int nState){m_nState=nState;}
  44.  
  45.         float FrontBumperDistance(){return m_fFrontBumperDistance;}
  46.         float BackBumperDistance(){return m_fBackBumperDistance;}
  47.         float LSideDistance(){return m_fLSideDist;}
  48.         float RSideDistance(){return m_fRSideDist;}
  49.         float VehicleWidth(){return m_fLSideDist+m_fRSideDist;}
  50.         float VehicleLength(){return m_fBackBumperDistance+m_fFrontBumperDistance;}
  51.  
  52.         short CheckPt(int nIdx);
  53.     
  54.         enum States{kForward,kBackup,kShortcut,kStop};
  55.         enum TargetTypes{kRoadTarget, kTurnTarget, kObstacleTarget, kBlockedTarget,};
  56.         enum ObstacleTypes{kPlayerObstacle,kAmbObstacle,kOppObstacle,kCopObstacle,kPedObstacle,kBangerObstacle};
  57.  
  58.     private:
  59.         int LocateWayPtFromRoad(aiPath *pCallLink);
  60.         int LocateWayPtFromInt(int nId);
  61.  
  62.         void SolveRoadTargetPoint();
  63.         void SolveShortcutTargetPoint();
  64.         int  PlanRoute();
  65.         void CalcRoute();
  66.         void CalcRoadTarget(int nRouteIdx,Vector3& Position);
  67.         void CalcDestinationTarget(int nRouteIdx,Vector3& Position);
  68.         void DestMapComponent(const Vector3& Pos,short *pnDestMapCompId,short *pnDestMapCompType);
  69.         void EnumRoutes(int nRouteIdx);
  70.         void ContinueCheck(int nRouteIdx);
  71.         void SaveTurnTarget(int nRouteIdx,int bDoAngleCalc);
  72.         void SaveTarget(int nRouteIdx,Vector3& Target,aiObstacle *pObstacle,short& Location,
  73.                         int nObsType,short& TargetType);
  74.         aiObstacle* IsTargetBlocked(Vector3& Pos,Vector3& Target,int nSVIdx,int nSRIdx,
  75.                                    int nTVIdx,int nTRIdx,float fMaxDist,int *pnType);
  76.         int CalcObstacleAvoidPoints(aiObstacle *pObstacle,int nRouteIdx,int bUseSidewalk,
  77.                                     Vector3 *pTargets,aiObstacle **ppAltObstacles,short* pLocations,
  78.                                     short* pTargetTypes);
  79.         void EnumTargets(Vector3& OrigTarget,aiObstacle *pOrigObstacle,int nRouteIdx,
  80.                          int nSRd,int nSVIdx,int nSide,int bUseSidewalk,int nNumTries,
  81.                          Vector3* pTargets,aiObstacle **ppAltObstacles,short* pLocations,
  82.                          short* pTargetTypes,int *pnNumTargets);
  83.         void DetermineBestRoute();
  84.     
  85.         void  CalcSpeed();
  86.         void  CalcRoadSpeed(); 
  87.         float CheckDistance(int nWhichTurn);
  88.  
  89.         void  InitRoadTurns();
  90.         void  CalcRoadTurns();
  91.         float CalcTurnIntersection(int nWhichTurn);
  92.  
  93.         void CheckForShortcut();
  94.         int  InSharpTurn(int nRouteIdx);
  95.         int  CalcSharpTurnTarget(int& nRouteIdx,int nLastIdx,Vector3& Position);
  96.  
  97.         void Stop();
  98.         void InitShortcut();
  99.         void Shortcut();
  100.         void InitBackup();
  101.         void Backup();
  102.         void FinishedBackingUp();
  103.         void SetTargetPtToDestination(int nRouteIdx);
  104.  
  105.         void InitForward();
  106.         void Forward();
  107.  
  108.         Vehicle m_Car;
  109.         bool m_bDir[3];
  110.         aiPath* m_pRoads[3];
  111.         aiPath* m_pPrevRoad;
  112.  
  113.         short m_nState;
  114.         short m_nLastState;
  115.  
  116.         enum { MAX_ROUTE_NODES = 40 };
  117.         enum { MAX_NUM_ROUTES = 25 };
  118.  
  119.         aiRouteNode m_Route[MAX_ROUTE_NODES];
  120.         aiRouteNode m_AltRoute[MAX_NUM_ROUTES][MAX_ROUTE_NODES];
  121.         int m_nBestRoute;
  122.         int m_naBlockedRoute[MAX_NUM_ROUTES];
  123.         int m_naOffRoadRoute[MAX_NUM_ROUTES];
  124.         int m_naNumRouteVerts[MAX_NUM_ROUTES];
  125.         int m_nNumRoutes;
  126.  
  127.         Vector3 m_Destination;
  128.         Vector3 m_DestHeading;
  129.         short m_nDestMapCompType;
  130.         short m_nDestMapCompId;
  131.         short m_bFinished;
  132.  
  133.         Vector3 m_TargetPt;
  134.         short *m_panWayPts;
  135.         short m_nNumWayPts;
  136.         short m_nWayPtIdx;
  137.         short m_nCurMapCompType;
  138.         short m_nCurMapCompIdx;
  139.         short m_nBackupCount;
  140.         short m_nRdIdx;
  141.  
  142.         float m_fBrake;
  143.         float m_fThrottle;
  144.         float m_fSteering; 
  145.         float m_fTurnCenterPtOffset;
  146.         float m_fRdAngle[2];
  147.         float m_fTurn[2];
  148.         Vector3 m_LPos;
  149.         Vector3 m_LPosition;
  150.         Vector3 m_IntersectionPt[2];
  151.         Vector3 m_TurnCenterPt[2];
  152.         Vector3 m_TurnStartDir[2];
  153.         Vector3 m_TurnEndDir[2];
  154.         float m_fTurnSetback[2];
  155.         float m_fRadius[2];
  156.  
  157.         float m_fSideDist;
  158.         float m_fDestSpeed;
  159.         float m_fDestOffset;
  160.  
  161.         float m_fFrontBumperDistance;
  162.         float m_fBackBumperDistance;
  163.         float m_fLSideDist;
  164.         float m_fRSideDist;
  165.  
  166.         float m_fTurnVelFactor;
  167.         float m_fBrakeThreshold;
  168.         float m_fRoutePlanDist;
  169. };
  170.  
  171. #endif
  172.